﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Paway.Windows.Forms;
using Paway.Windows.Forms.Metro;
using Paway.Windows.Helper;
using System.Configuration;
using Maticsoft.DBUtility;



using System.Text;
namespace Paway.Windows.Test
{
    public partial class Form1 : _360Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void toolBar1_SelectedIndexChanged(object sender, EventArgs e)
        {
            MessageBox.Show("下标改变了，当前下标为：" + this.toolBar1.SelectedIndex);
        }

        private void toolBar1_SelectedItemChanged(object sender, EventArgs e)
        {
            MessageBox.Show("项发生改变了，当前项为：" + this.toolBar1.SelectedItem);
        }

        private void panel3_Paint(object sender, PaintEventArgs e)
        {
            ControlPaint.DrawBorder(e.Graphics,
                                this.panel3.ClientRectangle,
                                Color.White,//左
                                1,
                                ButtonBorderStyle.None,
                                Color.DarkGray,//上
                                1,
                                ButtonBorderStyle.Solid,
                                Color.White,//右
                                1,
                                ButtonBorderStyle.None,
                                Color.DarkGray,//下
                                1,
                                ButtonBorderStyle.Solid);
        }

        private void panel4_Paint(object sender, PaintEventArgs e)
        {
            ControlPaint.DrawBorder(e.Graphics,
                                this.panel4.ClientRectangle,
                                Color.White,//左
                                1,
                                ButtonBorderStyle.None,
                                Color.DarkGray,//上
                                1,
                                ButtonBorderStyle.None,
                                Color.LightSeaGreen,//右
                                1,
                                ButtonBorderStyle.Solid,
                                Color.White,//下
                                1,
                                ButtonBorderStyle.None);
        }
        protected string GetIP()   //获取本地IP
        {
            System.Net.IPHostEntry IpEntry = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());
            for (int i = 0; i != IpEntry.AddressList.Length; i++)
            {
                if (IpEntry.AddressList[i].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    return IpEntry.AddressList[i].ToString();
                }
            }
            return "未成功获取..";
        }
        public static string GetAppSettingsValue(string key)
        {
            ConfigurationManager.RefreshSection("appSettings");
            return ConfigurationManager.AppSettings[key] ?? string.Empty;
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            //string strwbar_Name = GetAppSettingsValue("_mac");
            //string wbar_id = string.Empty;

            //DataSet ds = DbHelperMySQL.Query("select id  FROM in_wbar where  name='" + strwbar_Name + "'");
            //    string warid=string.Empty;
            //     if (ds.Tables[0].Rows.Count > 0)
            //     {
            //         warid = ds.Tables[0].Rows[0]["id"].ToString();
            //         DataSet dsuser_id = DbHelperMySQL.Query("select user_id  FROM in_wbar_user where  static_ip='" + GetIP() + "'and wbar_id='" + ds.Tables[0].Rows[0]["id"].ToString() + "'");

            //         if (dsuser_id.Tables[0].Rows.Count > 0)
            //         {
            //             label6.Text = dsuser_id.Tables[0].Rows[0][0].ToString();
                        
            //         }
            //         else
            //         {
            //             label6.Text = "本机IP有异常";
            //             return;
            //         }

            //     }
            //     else
            //     {

            //         MessageBox.Show("未初始化网吧");
            //     }
         
            //     DataSet ds1 = DbHelperMySQL.Query("select id,name  FROM in_wbar_class where  wbar_id='" + warid+ "'");
            //     lswc.DataSource = ds1.Tables[0]; ;//绑定数据源       
            //     lswc.ValueMember = "id";//设置ListBox中显示文本        
            //     lswc.DisplayMember = "name";//设置ListBox中文本Value       
            //     if(ds1.Tables[0].Rows.Count > 0)
            //     {
            //         DataSet dswbar_goods = DbHelperMySQL.Query("select name,price as Price FROM  in_wbar_goods where  wbar_class_id='" + ds1.Tables[0].Rows[0]["id"].ToString() + "'");
            //         dgvSteps.AutoGenerateColumns = false;
            //         int index = this.dgvSteps.Rows.Add();
                     
            //         this.dgvSteps.Rows[index].Cells[1].Value = "果粒橙";
            //         this.dgvSteps.Rows[index].Cells[2].Value = "8元";
            //         index = this.dgvSteps.Rows.Add();
                     
            //         this.dgvSteps.Rows[index].Cells[1].Value = "果粒橙";
            //         this.dgvSteps.Rows[index].Cells[2].Value = "8元";
            //         index = this.dataGridView1.Rows.Add();
                     
            //         this.dataGridView1.Rows[index].Cells[1].Value = "果粒橙";
            //         int coun = dgvSteps.RowCount;
            //         for (int i = 0; i < coun - 1; i++)
            //         {
            //             dgvSteps.Rows[i].Cells[0].Value = i + 1;
                       
            //         }

            //         dgvSteps.DataSource = dswbar_goods.Tables[0];
                     
            //         //foreach (DataRow dataRow in dswbar_goods.Tables[0].Rows)
            //         //{
            //         //    dgvSteps.Rows.Add(); //DataGridView在录入数据之前，需要首先增加自己的行的数量  
            //         //    int i = dgvSteps.Rows.Count; //获取DataGridView当前行数  
            //         //    object[] itemArray = dataRow.ItemArray; //获取dataRow的所有的单元格里的数据Array  
            //         //    //将dataRow的单元格数组数据一一填充到DataGridViewRow的Cell中  
            //         //    for (int j = 0; j < itemArray.Length; j++)
            //         //    {
            //         //        dgvSteps.Rows[i - 1].Cells[j].Value = itemArray[j].ToString();
            //         //    }
            //         //}
                    
           
                 
                 
            //     }
            DataTable newdtb = new DataTable();
           
            newdtb.Columns.Add("name", typeof(string));
            newdtb.Columns.Add("price", typeof(decimal));
            for (int i = 1; i < 11; i++)
            {
                DataRow newRow = newdtb.NewRow();
                newRow["name"] = "pro" + i.ToString();
                newRow["price"] = 12.3m;
                newdtb.Rows.Add(newRow);
            }
            dgvSteps.DataSource = newdtb;
   
            int coun = dgvSteps.RowCount;
            for (int i = 0; i < coun ; i++)
            {
                dgvSteps.Rows[i].Cells[0].Value = i + 1;

            }
            this.panel1.Controls.Clear();
            Form3 form =
new Form3();
            form.FormBorderStyle = FormBorderStyle.None; //隐藏子窗体边框（去除最小花，最大化，关闭等按钮）
            form.TopLevel =
            false; //指示子窗体非顶级窗体
            this.panel1.Controls.Add(form);//将子窗体载入panel
            form.Show();

           
        }

        private void panel7_Paint(object sender, PaintEventArgs e)
        {
            ControlPaint.DrawBorder(e.Graphics,
                                this.panel7.ClientRectangle,
                                Color.LightSeaGreen,//左
                                1,
                                ButtonBorderStyle.Solid,
                                Color.DarkGray,//上
                                1,
                                ButtonBorderStyle.None,
                                Color.LightSeaGreen,//右
                                1,
                                ButtonBorderStyle.None,
                                Color.White,//下
                                1,
                                ButtonBorderStyle.None);
        }

        private void dgvSteps_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //判断下单元格内容是不是第一列，也就是说单击的单元格内容是不是button列
            int k = e.ColumnIndex;
         
            if (k == 1)
            {
                //处理代码
                MessageBox.Show("ssss");
            }
           
        }

        private void LBHome_Click(object sender, EventArgs e)
        {
            BindData("");
        }

        private void LBUp_Click(object sender, EventArgs e)
        {
            BindData("up");
        }

        private void LBNext_Click(object sender, EventArgs e)
        {
            BindData("next");
        }
        private void Btn_Query_Click(object sender, EventArgs e)
        {
            string sqlstr = " where 1=1 ";
            
            HWhere.Text = sqlstr;
            BindData("");
        }
        private void LBEnd_Click(object sender, EventArgs e)
        {
            BindData("end");
        }
        public void BindData(string strClass)
        {
            int DataCount = 0;
            int NowPage = 1;
            int AllPage = 0;
            int PageSize = System.Convert.ToInt32(HPageSize.Text);
            switch (strClass)
            {
                case "next":
                    NowPage = System.Convert.ToInt32(HNowPage.Text) + 1;
                    break;
                case "up":
                    NowPage = System.Convert.ToInt32(HNowPage.Text) - 1;
                    break;
                case "end":
                    NowPage = System.Convert.ToInt32(HAllPage.Text);
                    break;
                case "refresh":
                    NowPage = System.Convert.ToInt32(HNowPage.Text);
                    break;
                case "jump":
                    NowPage = System.Convert.ToInt32(txtToPageIndex.Text);
                    break;
                default:
                    break;
            }
            //DataTable dsLog = BLL.bllCollegeInfo.GetCollegeInfo(NowPage, PageSize, out AllPage, out DataCount, HWhere.Text);
            DataTable dsLog = new DataTable();
            if (dsLog.Rows.Count == 0 || AllPage == 1)
            {
                
                LBNext.Enabled = false;
                LBUp.Enabled = false;
            }
            else if (NowPage == 1)
            {
              
                LBUp.Enabled = false;
                LBNext.Enabled = true;
               
            }
            else if (NowPage == AllPage)
            {
              
                LBUp.Enabled = true;
                LBNext.Enabled = false;
               
            }
            else
            {
               
                LBNext.Enabled = true;
                LBUp.Enabled = true;
            }
            this.dgvSteps.DataSource = dsLog.DefaultView;
            PageMes.Text = string.Format("[{0}／{1}]",  NowPage, AllPage);
            HNowPage.Text = System.Convert.ToString(NowPage++);
            HAllPage.Text = AllPage.ToString();

        }

        private void btnToPageIndex_Click(object sender, EventArgs e)
        {
            BindData("jump");
        }

        private void btsumit_Click(object sender, EventArgs e)
        {
            MessageBox.Show("333");
        }

        private void lswc_DoubleClick(object sender, EventArgs e)
        {
            if (this.lswc.SelectedItem != null )
            {
                //要做的事
                string lsse = this.lswc.SelectedItem.ToString();
          //      Maticsoft.BLL.in_wbar_goods bllingoods = new Maticsoft.BLL.in_wbar_goods();
             //  DataSet ds1 = bllingoods.GetList("")

            }
          
        }
       
    }
}
